# @Time : 2021/9/17 19:57
# @Author : jiangping
# @Email : jp@gmail.com
# @File : sort_page.py
# @Project : mryx_test
"""分类页面类"""
from page.base_page import BasePage
from appium.webdriver.common.mobileby import MobileBy as By
class SortPage(BasePage):
    """定义定位器"""
    recommend_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("推荐")')  # 推荐
    milk_sort_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("乳品烘焙")')  # 乳品烘焙
    search_locator = (By.ID, 'cn.missfresh.application:id/search_layout')  # 分类页搜索输入框
    search_input_locator = (By.XPATH, '//android.widget.EditText'
                                      '[@resource-id=\"cn.missfresh.application:id/search_view\"]')  # 搜索页搜素输入框
    search_btn_locatot = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("搜索")')  # 搜索按钮
    snacks_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("休闲零食")')  # 休闲零食
    nuts_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("坚果炒货")')  # 坚果炒货

    qk = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("清空")')  # 清空搜索历史记录
    sc = (By.XPATH, '//android.widget.ImageView[@resource-id=\"cn.missfresh.application:id/clear_his_view\"]')  # 删除历史记录
    scsp = (By.ID, 'cn.missfresh.application:id/tv_delete')  # 删除购物商品
    scqd = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("确定")')  # 确认删除

    # 断言
    # 搜索
    ssys = (
        By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/'
                  'android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/'
                  'android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/'
                  'android.widget.RelativeLayout[1]/android.widget.TextView[1]')
    # 历史记录
    qd = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("热门搜索")')
    # 购物清空
    gwqd = (By.XPATH,'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/'
                     'android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/'
                     'android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.View/'
                     'android.view.View/android.widget.LinearLayout[2]/android.widget.TextView')
    # 购物商品名
    spn = (By.XPATH,'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/'
                    'android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/'
                    'android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.View/'
                    'android.view.View/android.widget.LinearLayout[3]/android.widget.RelativeLayout/android.widget.TextView[1]')

    def recommend(self):
        """点击推荐"""
        self.driver.find_element(*self.recommend_locator).click()

    def milk_sort(self):
        """点击乳品烘焙"""
        self.driver.find_element(*self.milk_sort_locator).click()

    def click_search(self):
        """点击分类页搜索输入框"""
        self.driver.find_element(*self.search_locator).click()

    def input_keyword(self,keyword):
        """输入关键字"""
        self.driver.find_element(*self.search_input_locator).send_keys(keyword)

    def click_search_btn(self):
        """点击搜索"""
        self.driver.find_element(*self.search_btn_locatot).click()

    def click_snacks(self):
        """点击休闲零食"""
        self.driver.find_element(*self.snacks_locator).click()

    def click_nuts(self):
        """点击坚果炒货"""
        self.driver.find_element(*self.nuts_locator).click()

    def click_sc(self):
        """分类页面搜索后，删除"""
        self.driver.find_element(*self.sc).click()

    def click_qk(self):
        """分类页面搜索后，清空历史记录"""
        self.driver.find_element(*self.qk).click()

    def click_fladd(self):
        """点击分类页面-搜索后添加商品"""
        self.driver.tap([(301, 574), (340, 613)])

    def click_rdscadd(self):
        """点击分类页面-分类里添加商品"""
        self.driver.tap([(648, 405), (705, 441)])

    def click_gwc(self):
        """点击分类页面-购物车"""
        self.driver.tap([(638, 38), (720, 120)])

    def click_scsp(self):
        """点击分类页面-删除商品"""
        self.driver.find_element(*self.scsp).click()

    def click_scqd(self):
        """点击分类页面-删除商品"""
        self.driver.find_element(*self.scqd).click()

    def dy_search(self):
        """断言搜索功能"""
        return self.driver.find_element(*self.ssys).text

    def dy_lsjl(self):
        """断言历史记录功能"""
        return self.driver.find_element(*self.qd).text

    def dy_qksp(self):
        """断言清空商品"""
        return self.driver.find_element(*self.gwqd).text

    def dy_sp(self):
        """断言分类页加入商品"""
        return self.driver.find_element(*self.spn).text

